/**
 * 公共方法
 * author：jack
 * date：2018-07-03
 * */
import axios from 'axios';
/**
* 导出excel
* */
export const exportExcel = options => {
    if (!options) {
        return false;
    }
    let oParams = {
        method: options.method || 'post',
        url: options.url,
        responseType: 'blob'
    }
    if (options.method == 'GET' || options.method == 'get') {
        oParams.params = options.data
    } else {
        oParams.data = options.data;
    }
    console.log(options.data);
    axios(oParams).then(response => {
        if (!response) {
            return
        };
        let url = window.URL.createObjectURL(new Blob([response.data], {
            type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
        }));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', options.fileName || 'excel.xlsx');
        document.body.appendChild(link);
        link.click();
        if (options.success) {
            (options.success)();
        }
    }).catch((error) => {
        if (options.errorFunc) {
            (options.errorFunc)(error);
        }
    })
}

/**
* 下载zip
*/
export const downPackFile = options => {
    if (!options) {
        return false;
    };
    console.log(options)
    let iframe = document.createElement('a')
    iframe.style.display = 'none'
    iframe.href = options.url
    document.body.appendChild(iframe);
    iframe.click();
    //window.location.href = options.url;
}